package edu.buffalo.cse.cse486_586.entity;

import edu.buffalo.cse.cse486_586.service.MessageBean;
import edu.buffalo.cse.cse486_586.service.MessageProcessor;

public class VoteMessage implements Message {
	private String votedMessageId;
	private String purposedSequence;
	private int senderPort;
	private boolean isFinal;

	public VoteMessage() {
		this.isFinal = false;
	}

	public VoteMessage(String votedMessageId, String purposedSequence,
			int senderPort) {
		super();
		this.votedMessageId = votedMessageId;
		this.purposedSequence = purposedSequence;
		this.senderPort = senderPort;
		this.isFinal = false;
	}

	public String getVotedMessageId() {
		return votedMessageId;
	}

	public void setVotedMessageId(String votedMessageId) {
		this.votedMessageId = votedMessageId;
	}

	public String getPurposedSequence() {
		return purposedSequence;
	}

	public void setPurposedSequence(String purposedSequence) {
		this.purposedSequence = purposedSequence;
	}

	public int getSenderPort() {
		return senderPort;
	}

	public void setSenderPort(int senderPort) {
		this.senderPort = senderPort;
	}

	public boolean isFinal() {
		return isFinal;
	}

	public void setFinal(boolean isFinal) {
		this.isFinal = isFinal;
	}

	@Override
	public String toString() {
		// Example: 2 or 4/--/5556/--/5554_1:1
		StringBuilder str = new StringBuilder();
		if (this.isFinal()) {
			str.append(MessageBean.FINAL_MESSAGE);
		} else {
			str.append(MessageBean.VOTE_MESSAGE);
		}

		str.append(MessageProcessor.MESSAGE_SPLITTER).append(this.senderPort)
				.append(MessageProcessor.MESSAGE_SPLITTER)
				.append(this.votedMessageId).append(":")
				.append(this.purposedSequence);
		return str.toString();
	}
}
